package com.zhkj.txg.module.product.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zhkj.lib.utils.ScreenUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.product.adapter.ProductServiceAdapter
import com.zhkj.txg.module.product.entity.ServiceTagEntity
import razerdp.basepopup.BasePopupWindow

class ProductServiceTagPopup(context: Context) : BasePopupWindow(context) {

    init {
        popupGravity = Gravity.BOTTOM
    }

    override fun onCreateShowAnimation(): Animation = getTranslateVerticalAnimation(1f, 0f, 300)
    override fun onCreateDismissAnimation(): Animation = getTranslateVerticalAnimation(0f, 1f, 300)
    override fun onCreateContentView(): View = createPopupById(R.layout.popup_product_service)

    private lateinit var serviceAdapter: ProductServiceAdapter

    override fun onViewCreated(contentView: View?) {
        contentView?.let {
            // 设置ScrollView的高度
            it.findViewById<View>(R.id.rvProductService)?.layoutParams?.height =
                (ScreenUtil.getScreenHeight(context) * 0.75).toInt()
            it.findViewById<View>(R.id.ivClose).setOnClickListener { dismiss() }
            with(it.findViewById<RecyclerView>(R.id.rvProductService)) {
                serviceAdapter = ProductServiceAdapter()
                layoutManager = LinearLayoutManager(context)
                adapter = serviceAdapter
            }
        }
    }

    fun setData(data: MutableList<ServiceTagEntity>) {
        serviceAdapter.setNewData(data)
    }
}